/* 
 * 创建日期 2011-7-19
 *
 * 成都天和软件公司
 * 电话：028-85425861 
 * 传真：028-85425861-8008 
 * 邮编：610041 
 * 地址：成都市武侯区航空路6号丰德万瑞中心B座1001 
 * 版权所有
 */
package  org.fantasy.question.web.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import  org.fantasy.cpp.web.controller.AbstractController;
import  org.fantasy.common.util.ParamMap;
import  org.fantasy.common.util.RequestUtil;
import  org.fantasy.question.pojo.Question;
import  org.fantasy.question.service.QuestionService;

/** 
 * <p>Title: QuestionController</p>  
 * <p>Description: </p>  
 * <p>Copyright: Copyright (c) 2011-7-19</p>  
 * @author 沈飞 
 * @version 1.0 
 */
@Controller
public class QuestionController extends AbstractController {
	private static final Log log = LogFactory.getLog(QuestionController.class);
	
	@Autowired
	private QuestionService questionService;
	
	/**
	 * 页面初始化
	 * 
	 * @param pageId
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/question/page/questionEdit")
	public String questionEdit(Long id, ModelMap model) throws Exception {
		if (id != null) {
			Question bean = questionService.getQuestion(id);
			model.addAttribute("bean", bean);
		} else {
			Question bean = new Question();
			model.addAttribute("bean", bean);
		}
		return "/question/page/questionEdit";
	}
	
	/**
	 * 保存页面信息
	 * @param request
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/question/page/questionSave")
	public String questionSave(HttpServletRequest request, ModelMap model) throws Exception {
		log.info("保存问题信息!");
		ParamMap<String,Object> params = RequestUtil.getParamMap(request);
		questionService.saveQuestion(params);
		return result(model);
	}
	
	/**
	 * 删除问题的页面
	 * @param id
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/question/page/questionDel")
	public String questionDel(Long id, ModelMap model) throws Exception {
		if (id != null) {
			Question bean = questionService.getQuestion(id);
			bean.setState("X");
			questionService.saveQuestion(bean);
		}
		return ajax("{}",model);
	}
	
	/**
	 * 解决问题的页面
	 * @param id
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/question/page/questionResolve")
	public String questionResolve(Long id, ModelMap model) throws Exception {
		if (id != null) {
			Question bean = questionService.getQuestion(id);
			model.addAttribute("bean", bean);
		} 
		return "/question/page/questionResolve";
	}
	
	/**
	 * 保存问题解决方法
	 * @param id
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/question/page/questionResolveSave")
	public String questionResolveSave(Long id, String means, Long statusId,
			ModelMap model) throws Exception {
		if (id != null && !"".equals(means)) {
			Question bean = questionService.getQuestion(id);
			bean.setMeans(means);
			bean.setEndTime(new Date());
			bean.setStatusId(statusId);
			questionService.saveQuestion(bean);
		}
		return result(model);
	}
}
